<script type="text/javascript">
function checkPost(){
	if($("#posttitle").val().length <1){
		alert("图片库名称不能为空");
		return false;
	}
}
var deletePath = "<?php echo CController::createUrl('gallery/delete')?>";
function removeGallery(obj,id){
	var r1=confirm('你确定要删除这个图片库？');
	if(r1==true){
		var r2=confirm('这项操作会删除该图片库下所有图片！');
		if (r2==true){
			$(obj).parent().remove();
			window.path1=deletePath+"/id/"+id;
			$.ajax({
				url:deletePath+"/id/"+id
			});
		}
	}
}
</script>

<body>
<!-- Start of first page -->
<div data-role="page" id="foo">
	<div data-role="header" data-theme="b">
		<h1><?php echo Yii::app()->user->name?>的图片库</h1>
		<a href="#" data-icon="back" onclick="history.go(-1);">返回</a>
		<?php echo CHtml::link("用户",array("user/index"),array("data-role"=>"button","data-icon"=>"star"))?>
	</div>
	<?php if (count($galleries)<$maxsize):?>
	<a href="#add" data-transition="slideup" data-role='button' data-theme='b' data-icon='plus' data-inline='true' />新建图片库</a>
	<a href="#viewAll" data-transition="slideup" data-role='button' data-theme='b' data-icon='arrow-d' data-inline='true' />全部图片</a>
	<?php endif?>
	<div class="ui-body ui-body-e">
		<?php if (count($galleries)==0):?>
			<p>您还没有创建任何图片库</p>
		<?php endif?>
		<?php if (!empty($error)):?>
			<p><font color='red'>Error:<?php echo $error?></font></p>
		<?php endif?>
		<?php if(!empty($info)):?>
			<p><font color='green'>Info:<?php echo $info?></font></p>
		<?php endif?>
	</div>
	<div data-role="content">
	<ul data-role="listview" data-split-icon="delete" data-split-theme="d">
	<?php foreach ($galleries as $gallery):?>
		<li><a rel='external' href="<?php echo Yii::app()->createUrl('gallery/view', array('id'=>$gallery->id)); ?> ">
			<h4><?php echo $gallery->title;?></h4>
			<p><?php echo $gallery->description;?></p>
			</a>
			<a onclick='removeGallery(this,<?php echo $gallery->id?>)'></a>
		</li>
	<?php endforeach;?>
	</ul>
	</div>
	<?php $this->renderPartial("//site/footer")?>
	<!-- footer -->		
</div>

<?php if (count($galleries)<=$maxsize):?>
<div data-role="page" id="add">
	<div data-role="header" data-theme="b">
	<h1><?php echo Yii::app()->user->name?>的图片库</h1>
		<a href="#foo" data-transition="slidedown" data-icon="back">取消</a>
	</div>
<div data-role="content">
	<div data-role="collapsible" data-collapsed='false'
		style="width: 98%; border-bottom: 1px dashed #b7b7b7">
		<h3>注意</h3>
		<ul>
			<li>您可创建的图片库数量为：<?php echo $maxsize-count($galleries)?></li>
		</ul>
	</div>

	<div style="margin:5px 5px 5px 5px;">
	<?php echo CHtml::form('index','post',array("onsubmit"=>"return checkPost();","data-ajax"=>"false","name"=>"addform")); ?>
			<table style="width:90%">
				<tr>
					<td width=80px>标题：</td>
					<td><input type="text" id='posttitle' name="MemberGallery[title]" onclick="this.value=''"
						value="新图片库" />
					</td>
				</tr>
				<tr>
					<td>简介：</td>
					<td><textarea style='width: 95%; height: 100px;'
							name="MemberGallery[description]" id='postContent'
							onclick="this.innerHTML=''">简介..</textarea>
					</td>
				</tr>
				<tr>
					<td colspan='2'><input type='submit' data-theme='b' value='确定' data-icon='check'
						data-inline='true' />
					</td>
				</tr>
			</table>
	<?php echo CHtml::endForm(); ?>
	</div>
</div>

	<?php $this->renderPartial("//site/footer")?>
	<!-- footer -->
		
</div>
<?php endif?>

<!-- Start of first page -->
<div data-role="page" id="viewAll">
	<div data-role="header" data-theme="b">
		<h1>
			全部图片
		</h1>
		<a href="#" data-icon="back" onclick="javascript:history.go(-1);">返回</a>
		<a href="#foo" data-transition="slidedown" data-icon="back">列表</a>
	</div>
	<div data-role="content" style="padding: 0 0 0 0;">
	<?php foreach($photos as $photo):?>
		<div class='all_photo'>
		<?php $imageHtml= CHtml::image(Yii::app()->request->baseUrl."/images/gallery/{$photo->member_gallery_id}_{$photo->id}.png"); 
		echo CHtml::link($imageHtml,array("gallery/photo","id"=>$photo->id),array("data-transition"=>"pop","data-rel"=>"dialog" ));
		?>
		</div>
	<?php endforeach;?>
	</div>
		
	<?php $this->renderPartial("//site/footer")?>
	<!-- footer -->
		
</div>


</body>